package cn.edu.zafu.bigdata.yh;
public class ArithmeticExceptionDemo {

    // 定义divide方法
    public static double divide(int a, int b) {
        if (b == 0) {
            throw new ArithmeticException("除数不能为0");
        }
        return (double) a / b;
    }

    public static void main(String[] args) {
        try {
            // 调用divide方法
            int result = (int) divide(10, 0);
            System.out.println("结果是: " + result);
        } catch (ArithmeticException e) {
            // 捕获异常并输出提示信息
            System.out.println("发生错误: " + e.getMessage());
        }
    }
}
